package com.example.warehouse.mapper;


import com.example.warehouse.entity.User;
import com.example.warehouse.page.Page1;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

@Mapper
public interface userMapper{
    @Select("SELECT * FROM user_info WHERE user_code=#{usercode} and is_delete=0")
    public User findUserByCode(String usercode);

    List<User> FindUserByPage(@Param("page1") Page1 page1, @Param("user") User user);

    int findUserCount(User user);

    @Insert("insert into user_info (user_code, user_name, user_pwd, user_type, user_state, is_delete, create_by, create_time, update_by, update_time) " +
            "VALUES (#{userCode},#{userName},#{userPwd},#{userType},#{userState},#{isDelete},#{createBy},#{createTime},#{updateBy},#{updateTime})")
    void addUser(User user);

    @Update("update user_info set user_state=#{userState} where user_id=#{userId}")
    void updataSatae(int userId, String userState);

    @Delete("DELETE from user_info  where user_id=#{userId}")
    void deleteById(Integer userId);

    @Update("UPDATE user_info set user_name=#{userName},update_time=#{updateTime} where user_id=#{userId}")
    void updateUserById(String userName, int userId, Date updateTime);

    @Update("update user_info set user_pwd=#{originPwd} where user_id=#{userId}")
    void updateUserPwd(Integer userId, String originPwd);


    @Select("SELECT auth_id from role_auth ra,user_role  ur where ur.user_id=#{userId} AND ur.role_id=ra.role_id ")
    List<Integer> FindUserAuth(Integer userId);


}
